package leetcode.code1711;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	int mod = (int) 1e9 + 7;

	public int countPairs(int[] deliciousness) {
		int[] hash = new int[(1 << 21) + 1];
		long ans = 0;
		for (int i = 0; i < deliciousness.length; i++) {
			int cur = deliciousness[i];
			for (int j = 0; j <= 21; j++) {
				int num = 1 << j;
				if (num < cur) {
					continue;
				}
				ans += 1l * hash[num - cur];
				ans %= mod;
			}
			hash[cur]++;
		}
		return (int) ans;
	}

	@Override
	public void debug4() {
		System.out.println(1<<20);
		H.compare(1, this.countPairs(H.str2array3("[1048576,1048576]")));
		H.compare(4, this.countPairs(H.str2array3("[1,3,5,7,9]")));
		H.compare(15, this.countPairs(H.str2array3("[1,1,1,3,3,3,7]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
